/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package OtherPubs;

import Rout.GoBefore;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ByIdOrName;
import org.testng.annotations.*;

/**
 *
 * @author user
 */
public class ChUpdater {
    GoBefore browser = new GoBefore();    
    
    @BeforeMethod
    public void setup() throws Exception {
    browser.setChDrvPath("/home/user/Selenium_Server/chromedriver/");
    browser.setCurURL("chrome://chrome/");    
    browser.setFilename_exp(null);
    browser.setCssButton("#relaunch");
    browser.setXpButton("//*[@id=\"relaunch\"]");
    browser.setDetctButton(Boolean.FALSE);
    browser.setEnableSafeBrow(Boolean.FALSE);
    browser.setRepDir(getClass().getSimpleName());
    browser.setRemoteDriver("192.168.4.85");
    }
    
    @Test
    public void versionDetect() throws Exception{
        System.out.println("\n Run test: " + getClass().getSimpleName());
        browser.setUp();
        browser.getCurURL();
        try {
            browser.getDriver().get(browser.getCurURL());
            browser.getDriver().switchTo().defaultContent();
            System.out.println("Check update status....");
            Thread.sleep(10000);
            WebElement status;
            try {                
                try {
                    Thread.sleep(1000);
                    System.out.println("try css");
                    status = browser.getDriver().findElement(By.cssSelector("#update-status-message"));                    
                } catch (Exception e) {
                    try {
                        Thread.sleep(1000);
                        System.out.println("try xpath");
                        status = browser.getDriver().findElement(By.xpath("//*[@id=\"update-status-message\"]"));                        
                    } catch (Exception e4) {
                        try {
                            Thread.sleep(1000);
                            System.out.println("try text");
                            status = browser.getDriver().findElement(By.linkText("is up to date"));                            
                        } catch (Exception e3) {
                            try {
                                Thread.sleep(1000);
                                System.out.println("try id");
                                status = browser.getDriver().findElement(By.id("update-status-message"));
                            } catch (Exception e2) {
                                System.out.println("nothing is pass ;(");
                                status = null;
                                browser.Fail();
                            }
                        }
                    }
                }
            System.out.println(status.getText());
            browser.PassBut("ok");
            } catch (Exception e) {
                
            }
            
            
        } catch (Exception e) {
            System.out.println("!!!");
            browser.testRun();
            browser.Fail();            
        }                        
    }
    
    @AfterMethod
    public void ThearsDown() {
        browser.getDriver().quit();      
        
    }
    
    
    
    
}
